<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ include file="/jsp/common/utility/volti.jsp" %>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	ReadDAO readDao = (ReadDAO)ctx.getBean("ReadDAO");

	String pnStr = request.getParameter("pn");
	String keyword = request.getParameter("keyword");
	Integer uid = (Integer)session.getAttribute("id");
	Integer tid = (Integer)session.getAttribute("tid");
	
	int pn = 0;
	int pageSize = 10;
	
	if(pnStr != null && !"".equals(pnStr.trim())){
		try{
			pn = Integer.parseInt(pnStr);
		}catch(Exception e){
			pn = 0;
		}
	}
	
	List where = new ArrayList();
	where.add(new Object[]{"eq","teamId",tid});
	where.add(new Object[]{"eq","userId",uid});
	where.add(new Object[]{"eq","isRead",0});
	
	if(keyword != null && !"".equals(keyword)){
		where.add(new Object[]{"like", "m.msg", keyword});
	}
	
	Map map = readDao.getRead(pn, pageSize, 
			new String[][]{new String[]{"desc","date"}}, 
			where,
			new String[][]{new String[]{"","id"},new String[]{"","m.msg"},new String[]{"","m.date"}}, 
			new String[]{"msg"});
	
	request.setAttribute("map",map);
	
	int pageTotal = ((Integer)map.get("pageTotal")).intValue();
	int pageNo = ((Integer)map.get("pageNo")).intValue();
	
	List pageList=getPage(pageTotal,pageNo);
	request.setAttribute("pages",pageList);
	
	request.setAttribute("keyword",keyword);

	pageContext.forward("/vm/message/message_list.vm");
%>
